added SSCLI 1.0
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSWinFormSingleInstanceApp / MainForm.cs
blobec58d1ede4379b52b213f906891292914a112b5b
1 /****************************** Module Header ******************************\
2 * Module Name: MainForm.cs
3 * Project: CSWinFormSingleInstanceApp
4 * Copyright (c) Microsoft Corporation.
5 *
6 * The sample demonstrates how to achieve the goal that only
7 * one instance of the application is allowed in Windows Forms application..
8 *
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 * History:
14 * * 8/31/2009 3:00 PM Bruce Zhou Created
15 \***************************************************************************/
17 using System;
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using System.Data;
21 using System.Drawing;
22 using System.Linq;
23 using System.Text;
24 using System.Windows.Forms;
26 namespace CSWinFormSingleInstanceApp
28 public partial class MainForm : Form
30 #region fields
31 LoginForm loginEntry = new LoginForm();
32 string loginMsg = "";
33 event EventHandler LoginMsgChanged;
34 #endregion
36 #region Properties
37 public string LoginMsg
39 get { return loginMsg; }
40 set
42 if (value != loginMsg)
44 loginMsg = value;
45 OnLoginMsgChanged(EventArgs.Empty);
49 #endregion
51 #region Constructor
52 public MainForm()
54 InitializeComponent();
55 this.Load += new EventHandler(MainForm_Load);
56 this.StartPosition = FormStartPosition.CenterScreen;
59 #endregion
61 #region EventHandlers
62 void MainForm_Load(object sender, EventArgs e)
64 //show Login dialog
65 loginEntry.ShowDialog();
66 //display welcome message
67 DisplayWelcomeMessage();
68 //bind Text of lableUserStatus to LoginMsg property.
69 this.labelUserStatus.DataBindings.Add("Text", this, "LoginMsg");
71 private void buttonLogoff_Click(object sender, EventArgs e)
73 GlobleData.IsUserLoggedIn = false;
74 LoginMsg = "User Successfully logged off";
76 this.Visible = false;
77 loginEntry = new LoginForm();
78 if (loginEntry.ShowDialog() == DialogResult.OK)
80 if (this.Visible == false && GlobleData.IsUserLoggedIn)
82 this.Visible = true;
84 LoginMsg = "User Successfully logged in";
87 #endregion
89 #region HelperMethods
90 void DisplayWelcomeMessage()
92 string welcomeMsg = "Welcome to codeplex:" + GlobleData.UserName;
93 this.labelWelcomeMsg.Text = welcomeMsg;
94 LoginMsg ="User Successfully logged in";
98 void OnLoginMsgChanged(EventArgs e)
100 if (LoginMsgChanged != null)
102 LoginMsgChanged(this, e);
105 #endregion